<?php
/**
 * @package Joomla
 * @subpackage Component
 * @license GNU/GPL
 * @author Joomlart.com
 * @version 1.0
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view' );

/**
 * News View
 * @package Joomlart
 * @subpackage Components
 */
class janewsViewlayouttemplates extends JView 
{
	function display($tpl = null)
	{ 
		if($this->getLayout() == 'form') {
			$this->_displayForm($tpl);
			return;
		}
		
		global $mainframe, $option;
		
		$filter_order		= $mainframe->getUserStateFromRequest( "$option.filter_order",		'filter_order',		's.type',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( "$option.filter_order_Dir",	'filter_order_Dir',	'',				'word' );
		$lists['order_Dir']	= $filter_order_Dir;
		$lists['order']		= $filter_order;
		$limit		= $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
		$limitstart	= $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' );
		
		$model = $this->getModel();
		$group = JRequest::getVar('group','headline');
		$tmpls = $model->getLists($group,$filter_order, $filter_order_Dir, $limit, $limitstart);
		$total = $model->getTotal();
		
		jimport('joomla.html.pagination');
		$pageNav = new JPagination( $total, $limitstart, $limit );
		
		$task = isset($_REQUEST['task'])?$_REQUEST['task']:'';
		
		$this->assignRef( 'tmpls', $tmpls);
		$this->assignRef('lists', $lists);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('task', $task);
		$this->assignRef('group', $group);
		parent::display($tpl);
	}
	
	function _toolbarDefault()
	{
		$document = & JFactory::getDocument();
		$document->setTitle( JText::_('Layout Templates Manager') );
		JToolBarHelper::title( JText::_( 'LAYOUT TEMPLATES MANAGER' ), 'generic.png' );
		JToolBarHelper::deleteList();
		JToolBarHelper::editListX();
		JToolBarHelper::addNewX();
	}
	
	function _toolbarEdit($edit=false)
	{		
		$text = ( $edit ? JText::_( 'EDIT' ) : JText::_( 'NEW' ) );
		JToolBarHelper::title(  JText::_( 'LAYOUT TEMPLATES' ).': <small><small>[ ' . $text.' ]</small></small>', 'generic.png' );
		if ($edit) {
		  JToolBarHelper::save();
		  JToolBarHelper::apply();
		  JToolBarHelper::cancel('cancel','Close');
		}
		else {
		  JToolBarHelper::custom('next','forward','forward','Next',false,false);
		  JToolBarHelper::cancel();
		}
	}
	
	function _displayForm($tpl)
	{
		$model = $this->getModel();
		
		$templates = $model->getLayoutTemplates();
		$tmpl_type = $model->getListType();
		$tmpls = JRequest::getVar('cid',  0, '', 'array');
		$group = JRequest::getVar('group','headline');
		$cid = (int)$tmpls[0];
		if (JRequest::getVar('task')=='next'){
		  $tmpl = new stdClass();
		  $tmpl->title = JRequest::getVar('title');
		  $tmpl->type = JRequest::getVar('tmpl_type');
		  $tmpl->template = JRequest::getVar('template');
		  $file 	= JPATH_COMPONENT_SITE.DS.'layouts'.DS.$tmpl->type.DS.$tmpl->template.DS.'params.xml';
  		$params = new JParameter( '', $file );
		}else {
  		$tmpl =& JTable::getInstance( 'janews_templates', 'Table' );
  		$tmpl->load($cid);
  		$file 	= JPATH_COMPONENT_SITE.DS.'layouts'.DS.$tmpl->type.DS.$tmpl->template.DS.'params.xml';
  		$params = new JParameter( $tmpl->params, $file );
		}
		
		$this->assignRef('cid', $cid);
		$this->assignRef('group', $group);
		$this->assignRef('tmpl', $tmpl);
		$this->assignRef('tmpl_type', $tmpl_type);
		$this->assignRef('params', $params);
		$this->assignRef('templates', $templates);
		parent::display($tpl);
	}
	
}
?>